package com.cskaoyan.controller.wx.cqw;

import com.cskaoyan.module.bean.BaseRespVo;
import com.cskaoyan.module.bo.wx.cqw.WxGoodsListBO;
import com.cskaoyan.module.pojo.MarketAdmin;
import com.cskaoyan.module.pojo.MarketUser;
import com.cskaoyan.service.wx.cqw.WxHomeIndexService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("wx")
public class WxHomeIndex {
    @Autowired
    WxHomeIndexService wxHomeIndexService;


    @GetMapping("home/index")
    @ResponseBody


    public BaseRespVo wxHomeIndex(){

    return wxHomeIndexService.getIndex();
    }
    @GetMapping("goods/count")
    public BaseRespVo  wxGoodsCount(){
        return wxHomeIndexService.getGoodsCount();
    }
///wx/goods/category
    @GetMapping("goods/category")
    public BaseRespVo wxGoodsCategory(Integer id){
        return wxHomeIndexService.getCategorylistByPid(id);
    }
    //wx/goods/list?categoryId=1008005&page=1&size=100
    //http://localhost:8083/wx/goods/list?brandId=1001000&page=1&limit=10
    @GetMapping("goods/list")
    public BaseRespVo wxGoodsList(WxGoodsListBO wxGoodsListBO) {
        BaseRespVo baseRespVo;
        if (wxGoodsListBO.getBrandId() != null ) {
            baseRespVo = wxHomeIndexService.getGoodsListByBrandId(wxGoodsListBO);
        } else {
            baseRespVo = wxHomeIndexService.getGoodsList(wxGoodsListBO);
        }

        return baseRespVo;
    }

    private BaseRespVo parameterValidation(BindingResult bindingResult) {
        FieldError fieldError = bindingResult.getFieldError();
        //拿到请求参数名
        String field = fieldError.getField();
        //传入的错误的值
        Object rejectedValue = fieldError.getRejectedValue();
        String defaultMessage = fieldError.getDefaultMessage();
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("请求参数").append(field).
                append("因为传入了").append(rejectedValue).
                append("导致异常").append(defaultMessage);
        return BaseRespVo.invalidData(stringBuffer.toString());
    }
    //wx/goods/detail
    @GetMapping("goods/detail")
    public BaseRespVo wxGoodsDetail(Integer id){





      return   wxHomeIndexService.getWxGoodsDetail(id);
    }

     //       wx/goods/related
@GetMapping("goods/related")
    public BaseRespVo wxGoodsRelated(Integer id){

    return   wxHomeIndexService.getWxGoodsRelated(id);
}

}
